<template>
  <div class="app-container">
    <div class="table-page-search-wrapper">
      <el-form :inline="true" label-width="100px">
        <el-row :gutter="18">
          <el-col :md="8" :sm="24">
            <el-form-item label="客户">
              <el-select
                v-model="queryParam.customerId"
                placeholder="请选择客户"
                filterable
                @change="onSearch"
              >
                <el-option
                  v-for="(item, index) in more.customerOptions"
                  :key="index"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :md="8" :sm="24">
            <el-form-item label="产品">
              <el-select
                v-model="queryParam.goodsId"
                placeholder="请选择产品"
                filterable
                @change="onSearch"
              >
                <el-option
                  v-for="(item, index) in more.goodsOptions"
                  :key="index"
                  :value="item.value"
                  :label="item.label"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="advanced">
            <el-col :md="8" :sm="24">
              <el-form-item label="状态">
                <el-select
                  v-model="queryParam.status"
                  placeholder="请选择状态"
                  clearabe
                  @change="onSearch"
                >
                  <el-option
                    v-for="(item, index) in more.orderStatusOptions"
                    :key="index"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
             <el-col :md="8" :sm="24">
              <el-form-item label="创建时间">
                <el-date-picker
                  v-model="queryParam.createTimeList"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :md="8" :sm="24">
              <el-form-item label="订单号">
                <el-select
                  v-model="queryParam.ordersId"
                  placeholder="请选择订单号"
                  clearabe
                  @change="onSearch"
                >
                  <el-option
                    v-for="(item, index) in more.ordersOptions"
                    :key="index"
                    :value="item.value"
                    :label="item.label"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <!--<el-col :md="8" :sm="24">
              <el-form-item label="更新时间">
                <el-date-picker
                  v-model="queryParam.updateTime"
                  clearable
                  type="date"
                  value-format="yyyy-MM-dd"
                  @change="onSearch"
                />
              </el-form-item>
            </el-col> -->
          </template>
          <el-col :md="!advanced && 8 || 24" :sm="24">
            <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
              <el-button v-waves type="primary" icon="el-icon-search" @click="onSearch">
                查询
              </el-button>
              <el-button type="info" icon="el-icon-refresh" @click="reset">
                重置
              </el-button>
              <el-link type="primary" :underline="false" @click="toggleAdvanced">
                {{ advanced ? '收起' : '展开' }}
                <i :class="advanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'" />
              </el-link>
            </span>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="table-operator">
      <el-button v-permission="['create']" type="primary" icon="el-icon-plus" @click="$refs.form.open(undefined)">
        新建
      </el-button>
       <el-button v-permission="['import']" icon="el-icon-upload2" @click="$refs.import.open()">
        导入
      </el-button>
      <!--<el-button v-permission="['export']" :icon="exportLoadingData ? 'el-icon-loading' : 'el-icon-download'" @click="exportData">
        导出
      </el-button> -->
    </div>

    <el-table
      v-loading="loadingData"
      :data="list"
      element-loading-text="Loading"
      fit
      highlight-current-row
      row-key="id"
      height="100%"
      @sort-change="appendSorterParam"
    >
    <el-table-column align="center" label="订单号">
        <template slot-scope="scope">
          <span>
            {{ scope.row.ordersId }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="客户">
        <template slot-scope="scope">
          <span>
            {{ scope.row.customerName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="产品名称">
        <template slot-scope="scope">
          <span>
            {{ scope.row.goods.name }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="状态">
        <template slot-scope="scope">
          <span>
            {{ scope.row.statusLabel }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="尺寸">
        <template slot-scope="scope">
          <span>
            {{ scope.row.skuSize }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="数量">
        <template slot-scope="scope">
          <span>
            {{ scope.row.quantity }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="附件">
        <template slot-scope="scope">
          <span>
            {{ scope.row.ext }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="附件数量">
        <template slot-scope="scope">
          <span>
            {{ scope.row.extQuantity }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建时间">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="更新时间">
        <template slot-scope="scope">
          <span>{{ scope.row.updateTime }}</span>
        </template>
      </el-table-column>
      
      <el-table-column align="center" label="创建人">
        <template slot-scope="scope">
          <span>
            {{ scope.row.createByName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="更新人">
        <template slot-scope="scope">
          <span>
            {{ scope.row.updateByName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button
            v-permission="['detail']"
            type="text"
            @click="$refs.detail.open(row.id)"
          >
            详情
          </el-button>
          <span
            v-permission="['detail']"
            v-permission-again="['update', 'delete']"
          >
            <el-divider
              direction="vertical"
            />
          </span>
          <el-dropdown
            v-permission="['update', 'delete']"
            @command="command => menuCommand(command, row)"
          >
            <el-button type="text">
              更多<i class="el-icon-arrow-down el-icon--right" />
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item
                v-permission="['update']"
                command="update"
                icon="el-icon-edit"
              >
                编辑
              </el-dropdown-item>
              <el-dropdown-item
                v-permission="['delete']"
                command="delete"
                icon="el-icon-delete"
              >
                删除
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pagination.total>0"
      :total="pagination.total"
      :page.sync="pagination.current"
      :limit.sync="pagination.pageSize"
      :style="{textAlign: 'right'}"
      @pagination="handlePaginationChanged"
    />

    <diboot-form ref="form" @complete="getList" />
    <diboot-detail ref="detail" />
    <diboot-import ref="import" @complete="getList" />
  </div>
</template>

<script>
import list from '@/components/diboot/mixins/list'
import dibootForm from './form'
import dibootDetail from './detail'
import dibootImport from './excelImport'
import waves from '@/directive/waves'
export default {
  name: 'OrderSkuList',
  directives: { waves },
  components: {
    dibootForm,
    dibootImport,
    dibootDetail
  },
  mixins: [list],
  data() {
    return {
      baseApi: '/orderSku',
      getListFromMixin: true,
      attachMoreList: [
        {
          target: 'customer',
          label: 'name',
          value: 'id'
        },
		    {
          target: 'goods',
          label: 'name',
          value: 'id'
        },
        {
          target: 'orders',
          label: 'id',
          value: 'id'
        },
        {
          target: 'orderStatus'
        }
      ]
    }
  },
  methods: {
    async returnOrder(row) {
      return new Promise((resolve, reject) => {
        const _this = this
        this.$confirm('确定退货该数据吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const values = {"status":"4"}
          const updateApiPrefix = this.updateApiPrefix ? this.updateApiPrefix : ''
          // const res = await dibootApi.put(`${this.baseApi}${updateApiPrefix}/${this.form[this.primaryKey]}`, values)
          dibootApi.put(`${this.baseApi}${updateApiPrefix}/${row.id}`, values).then(async(res) => {
            if (res.code === 0) {   
              _this.$message.success('当前数据成功')
              await _this.getList()
              resolve(res.data)
            } else {
              this.$notify.error({
                title: '失败',
                message: res.msg
              })
              reject(res.msg)
            }
          }).catch(err => {
            this.$notify.error({
              title: '失败',
              message: err
            })
            reject(err.msg)
          })
        })
      })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
